package com.sniper.springmvc.action.home;

import com.sniper.springmvc.mybatis.service.impl.JyzxReceiveService;
import com.sniper.springmvc.searchUtil.BaseSearch;
import com.sniper.springmvc.utils.PageUtil;
import com.sniper.springmvc.utils.ValidateUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
public class IndexController extends HomeBaseController {


    @Resource
    JyzxReceiveService receiveService;

    @RequestMapping("")
    public ModelAndView index(Map<String, Object> map, BaseSearch search) {

        Map<String, Object> params = new HashMap<>();

        if (ValidateUtil.isValid(search.getName())) {
            params.put("entname", search.getName());
        }

        PageUtil page = receiveService.page(request, 30, params);
        map.put("page", page);
        map.put("search", search);

        ModelAndView view = new ModelAndView();
        view.setViewName("/home/index/index");
        return view;
    }

    /**
     * 数据反馈
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "back", method = RequestMethod.GET)
    public String back(Map<String, Object> map) {

        return "home/index/back.ftl";
    }


}
